package org.example;

import com.atlassian.config.ApplicationConfig;
import com.atlassian.confluence.license.DefaultLicenseService;
import com.atlassian.confluence.license.store.ApplicationConfigurationLicenseStore;
import com.atlassian.confluence.license.validator.DataCenterNumberOfUsersValidator;
import com.atlassian.extras.api.AtlassianLicense;
import com.atlassian.extras.api.Product;
import com.atlassian.extras.api.ProductLicense;
import com.atlassian.extras.api.confluence.ConfluenceLicense;
import com.atlassian.extras.core.DefaultAtlassianLicenseFactory;
import com.atlassian.extras.core.DefaultLicenseManager;
import com.atlassian.extras.core.ProductLicenseFactory;
import com.atlassian.extras.core.confluence.ConfluenceProductLicenseFactory;
import com.atlassian.extras.decoder.api.LicenseDecoder;
import com.atlassian.extras.decoder.v2.Version2LicenseDecoder;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class ConfluenceProductLicenseTest {

    public static void main(String[] args) {
        ApplicationConfig applicationConfig = new ApplicationConfig();
        LicenseDecoder licenseDecoder = new Version2LicenseDecoder();
        ConfluenceProductLicenseFactory confluenceProductLicenseFactory = new ConfluenceProductLicenseFactory();
        Map<Product, ProductLicenseFactory> productLicenseFactoryMap = new HashMap<>();
        // #{T(com.atlassian.extras.api.Product).CONFLUENCE}
        productLicenseFactoryMap.put(Product.CONFLUENCE, confluenceProductLicenseFactory);
        DefaultAtlassianLicenseFactory atlassianLicenseFactory = new DefaultAtlassianLicenseFactory(productLicenseFactoryMap);
        DefaultLicenseManager licenseManager = new DefaultLicenseManager(licenseDecoder, atlassianLicenseFactory);
        ApplicationConfigurationLicenseStore store = new ApplicationConfigurationLicenseStore(applicationConfig, licenseManager);
        DataCenterNumberOfUsersValidator dataCenterNumberOfUsersValidator = new DataCenterNumberOfUsersValidator();
        DefaultLicenseService defaultLicenseService = new DefaultLicenseService(store, licenseManager, dataCenterNumberOfUsersValidator, atlassianLicenseFactory);
        String license = "";
//        AtlassianLicense atlassianLicense = defaultLicenseService.decodeAndValidateLicense(license);
//        ConfluenceLicense validate = defaultLicenseService.validate(license);
//        System.out.println(atlassianLicense);
        Optional<ProductLicense> productLicense = defaultLicenseService.retrieveForProduct(Product.CONFLUENCE);
        ProductLicense productLicense1 = productLicense.get();
        System.out.println(productLicense1);
//        log.info("{}", validate);
    }
}
